<?php

namespace app\interfaces\model;

use app\interfaces\model\MemberCollect as MemberCollectModel;
use think\Request;
use think\Model;

class ShopGoods extends Model
{
    // 套餐状态
    protected function ggetGoodsAttrAttr($value, $data)
    {
        return arrayChange(unserialize($data['goods_attr']), 'title', 'list');
    }

        protected function getGoodsAttrAttr($value, $data)
    {
        $goods_str =  unserialize($data['goods_attr']);
        $arr = '';
       if($goods_str){
           foreach ($goods_str as $k => &$v) {
               if (count($v) >= 1) {
                   $first = reset($v);
                   $arr .=  $first.',';
//                $first_key = key($v);
//                $v = [$first_key => $first];

               }
           }
           $arr = rtrim($arr,',');
       }else{
           $arr = '';
       }
//        var_dump($goods_str);
      return $arr;

        return arrayChange($goods_str, 'title', 'list');

    }

    // 收藏状态
    protected function getCollectionStatusAttr($value, $data)
    {
        $id = MemberCollectModel::where(['collect_id' => $data['id'], 'member_id' => Request::instance()->param('user_id'), 'type_id' => '1'])->value('id');

        return $id ? '1' : '2';
    }
}
